﻿<UserControl x:Class="Deployment.Data.SQL.Connections.UI.SQLServerControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:w="clr-namespace:Deployment.Data;assembly=Deployment.Data"
             mc:Ignorable="d" 
             d:DesignHeight="291" d:DesignWidth="300"
             MinWidth="300">
    <UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="boolToVisConverter"/>
    </UserControl.Resources>
    <StackPanel Orientation="Vertical" >
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            
            <Label Content="Server name:"
                   Grid.Row="0" Grid.Column="0"/>
            <ComboBox Text="{Binding SQLServer}" Margin="4,0,4,4" x:Name="cbo_Servers"
                      Grid.Row="1" Grid.Column="0" 
                      IsEditable="True" 
                      DropDownOpened="cbo_Servers_DropDownOpened" 
                      SelectedValue="{Binding Path=SQLServer, Mode=TwoWay}"
                      VerticalAlignment="Center"/>
            <Button Content="Refresh" Margin="4,0" x:Name="btn_refresh"
                    Grid.Row="1" Grid.Column="1" Height="22" VerticalAlignment="Center"
                    Click="Refresh_Click"/>
        </Grid>
        <GroupBox Header="Log on to the server">
            <StackPanel Orientation="Vertical" Margin="4,8,4,4">
                <RadioButton Content="Use Windows Authentication" x:Name="rbt_WinAuth" IsChecked="{Binding Path=IntegratedSecurity, FallbackValue=True, Mode=TwoWay}" Margin="4,0,4,2"/>
                <RadioButton Content="Use SQL Server Authentication" x:Name="rbt_SQLAuth" Margin="4,2,4,4"/>
                <Grid Margin="12,0,0,0" IsEnabled="{Binding ElementName=rbt_SQLAuth, Path=IsChecked}"> 
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Label Content="User name:" Margin="4,0,4,2"
                           Grid.Row="0" Grid.Column="0"/>
                    <TextBox Margin="4,0,4,2" Text="{Binding Path=User, Mode=TwoWay}"
                        Grid.Row="0" Grid.Column="1"/>
                    <Label Content="Password:" Margin="4,2,4,0" 
                           Grid.Row="1" Grid.Column="0"/>
                    <PasswordBox x:Name="PasswordBox" Margin="4,2,4,0"
                                 Grid.Row="1" Grid.Column="1"
                                 w:PasswordHelper.Attach="True" 
                                 w:PasswordHelper.Password="{Binding Path=Password, Mode=TwoWay}"
                                 />
                    <TextBlock Grid.Row="2" Grid.Column="1"
                               Text="Warning!!! SQL authenticated passwords will be stored in plain text in the Environments file."
                               Foreground="Red"
                               TextWrapping="WrapWithOverflow"
                               MaxWidth="200"
                               Visibility="{Binding ElementName=PasswordBox, Path=IsEnabled, Converter={StaticResource ResourceKey=boolToVisConverter}}"/>
                </Grid>
            </StackPanel>
        </GroupBox>
    </StackPanel>
</UserControl>
